Skip to contentSkip to conversation

Change in openvpn[master]: t_server_null: forcibly kill misbehaving servers

Openvpn-devel In review mattock (Code Review) 2 participants 18 messages Oct 4, 2024 – Oct 25, 2024 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1728021620000.Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb@...2715...

#1 lore raw

Attention is currently required from: flichtenheld, plaisthos.

Hello plaisthos, flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/775?usp=email

to review the following change.

Change subject: t_server_null: forcibly kill misbehaving servers
......................................................................

t_server_null: forcibly kill misbehaving servers

Change-Id Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb

---
M tests/t_server_null_server.sh

1 file changed, 2 insertions(+), 2 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/75/775/1

tests/t_server_null_server.sh +2 -2
index 10bb44b..dea2a04 100755
@@ -88,9 +88,9 @@
     fi
 
     if [ -z "${RUN_SUDO}" ]; then
-        $KILL_EXEC "${SERVER_PID}"
+        $KILL_EXEC -15 "${SERVER_PID}" || $KILL_EXEC -9 "${SERVER_PID}"
     else
-        $RUN_SUDO $KILL_EXEC "${SERVER_PID}"
+        $RUN_SUDO $KILL_EXEC -15 "${SERVER_PID}" || $RUN_SUDO $KILL_EXEC -9 "${SERVER_PID}"
     fi
 
     count=0

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/775?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb
Gerrit-Change-Number: 775
Gerrit-PatchSet: 1
Gerrit-Owner: mattock <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, mattock, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/775?usp=email )

Change subject: t_server_null: forcibly kill misbehaving servers
......................................................................

Patch Set 1: Code-Review-2

(1 comment)

Patchset:

PS1:
this does not work the way it is intended

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/775?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb
Gerrit-Change-Number: 775
Gerrit-PatchSet: 1
Gerrit-Owner: mattock <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mattock <[email protected]...>
Gerrit-Comment-Date: Fri, 04 Oct 2024 06:45:15 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, mattock, plaisthos.

Hello cron2, flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/775?usp=email

to look at the new patch set (#2).

Change subject: t_server_null: forcibly kill misbehaving servers
......................................................................

t_server_null: forcibly kill misbehaving servers

Change-Id Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb

---
M tests/t_server_null_server.sh

1 file changed, 8 insertions(+), 1 deletion(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/75/775/2

tests/t_server_null_server.sh +8 -1
index 10bb44b..5fab897 100755
@@ -87,6 +87,7 @@
         continue
     fi
 
+    # Attempt to kill the OpenVPN server gracefully with SIGTERM
     if [ -z "${RUN_SUDO}" ]; then
         $KILL_EXEC "${SERVER_PID}"
     else
@@ -102,7 +103,13 @@
         sleep 0.2
     done
 
+    # If server is still up send a SIGKILL
     if [ $count -ge $maxcount ]; then
-        echo "WARNING: could not kill server with pid ${SERVER_PID}!"
+        if [ -z "${RUN_SUDO}" ]; then
+            $KILL_EXEC -9 "${SERVER_PID}"
+        else
+            $RUN_SUDO $KILL_EXEC -9 "${SERVER_PID}"
+        fi
+        echo "WARNING: had to send SIGKILL to server with pid ${SERVER_PID}!"
     fi
 done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/775?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb
Gerrit-Change-Number: 775
Gerrit-PatchSet: 2
Gerrit-Owner: mattock <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mattock <[email protected]...>
Gerrit-MessageType: newpatchset

#4 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, mattock, plaisthos.

Hello cron2, flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/775?usp=email

to look at the new patch set (#3).

Change subject: t_server_null: forcibly kill misbehaving servers
......................................................................

t_server_null: forcibly kill misbehaving servers

Change-Id Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb

---
M tests/t_server_null_server.sh

1 file changed, 5 insertions(+), 6 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/75/775/3

tests/t_server_null_server.sh +5 -6
index 10bb44b..b85d145 100755
@@ -87,11 +87,8 @@
         continue
     fi
 
-    if [ -z "${RUN_SUDO}" ]; then
-        $KILL_EXEC "${SERVER_PID}"
-    else
-        $RUN_SUDO $KILL_EXEC "${SERVER_PID}"
-    fi
+    # Attempt to kill the OpenVPN server gracefully with SIGTERM
+    $RUN_SUDO $KILL_EXEC "${SERVER_PID}"
 
     count=0
     maxcount=75
@@ -102,7 +99,9 @@
         sleep 0.2
     done
 
+    # If server is still up send a SIGKILL
     if [ $count -ge $maxcount ]; then
-        echo "WARNING: could not kill server with pid ${SERVER_PID}!"
+        $RUN_SUDO $KILL_EXEC -9 "${SERVER_PID}"
+        echo "WARNING: had to send SIGKILL to server with pid ${SERVER_PID}!"
     fi
 done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/775?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb
Gerrit-Change-Number: 775
Gerrit-PatchSet: 3
Gerrit-Owner: mattock <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mattock <[email protected]...>
Gerrit-MessageType: newpatchset

#5 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, mattock, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/775?usp=email )

Change subject: t_server_null: forcibly kill misbehaving servers
......................................................................

Patch Set 3: Code-Review-2

(2 comments)

Patchset:

PS3:
getting close... but I really think we should error out and include diagnostics if "kill -9" is necessary.

File tests/t_server_null_server.sh:

http://gerrit.openvpn.net/c/openvpn/+/775/comment/e8a12af1_7c789c6a :
PS3, Line 106: fi
I think we should make this a "test fail". If the server needs to be hard killed, something is wrong with the server, and we should look in the (soon-persistent :-) ) logs.

Maybe we could even output a "tail -20" or so of the logfile in this case, so failures can be investigated without logging into the machine?

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/775?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb
Gerrit-Change-Number: 775
Gerrit-PatchSet: 3
Gerrit-Owner: mattock <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mattock <[email protected]...>
Gerrit-Comment-Date: Wed, 23 Oct 2024 20:57:59 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#6 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, mattock, plaisthos.

Hello cron2, flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/775?usp=email

to look at the new patch set (#4).

Change subject: t_server_null: forcibly kill misbehaving servers
......................................................................

t_server_null: forcibly kill misbehaving servers

Change-Id Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb

---
M tests/t_server_null.sh
M tests/t_server_null_default.rc
M tests/t_server_null_server.sh

3 files changed, 21 insertions(+), 7 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/75/775/4

tests/t_server_null.sh +7 -1
index 7627edf..8fe1660 100755
@@ -67,4 +67,10 @@
 # pre and post ifconfig output does not match.
 wait
 
-exit $retval
+. ./t_server_null_default.rc
+
+if [ -e $SERVER_KILL_FAIL_FILE ]; then
+    exit 1
+else
+    exit $retval
+fi
tests/t_server_null_default.rc +4 -0
index 825bb52..cbf4877 100755
@@ -20,6 +20,10 @@
 SERVER_KEY="${sample_keys}/server.key"
 TA="${sample_keys}/ta.key"
 
+# Used to detect if graceful kill of any server instance failed during the test
+# run
+SERVER_KILL_FAIL_FILE=".t_server_null_server.kill_failed"
+
 # Test server configurations
 MAX_CLIENTS="10"
 CLIENT_MATCH="Test-Client"
tests/t_server_null_server.sh +10 -6
index 10bb44b..58c711f 100755
@@ -36,6 +36,9 @@
 # Load local configuration, if any
 test -r ./t_server_null.rc && . ./t_server_null.rc
 
+# Remove server kill failure marker file, if any
+rm -f $SERVER_KILL_FAIL_FILE
+
 # Launch test servers
 for SUF in $TEST_SERVER_LIST
 do
@@ -77,6 +80,7 @@
 # Make sure that the server processes are truly dead before exiting.  If a
 # server process does not exit in 15 seconds assume it never will, move on and
 # hope for the best.
+
 echo "Waiting for servers to exit"
 for PID_FILE in $server_pid_files
 do
@@ -87,11 +91,8 @@
         continue
     fi
 
-    if [ -z "${RUN_SUDO}" ]; then
-        $KILL_EXEC "${SERVER_PID}"
-    else
-        $RUN_SUDO $KILL_EXEC "${SERVER_PID}"
-    fi
+    # Attempt to kill the OpenVPN server gracefully with SIGTERM
+    $RUN_SUDO $KILL_EXEC "${SERVER_PID}"
 
     count=0
     maxcount=75
@@ -102,7 +103,10 @@
         sleep 0.2
     done
 
+    # If server is still up send a SIGKILL
     if [ $count -ge $maxcount ]; then
-        echo "WARNING: could not kill server with pid ${SERVER_PID}!"
+        $RUN_SUDO $KILL_EXEC -9 "${SERVER_PID}"
+        echo "ERROR: had to send SIGKILL to server with pid ${SERVER_PID}!"
+        touch $SERVER_KILL_FAIL_FILE
     fi
 done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/775?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb
Gerrit-Change-Number: 775
Gerrit-PatchSet: 4
Gerrit-Owner: mattock <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mattock <[email protected]...>
Gerrit-MessageType: newpatchset

#7 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, mattock, plaisthos.

Hello cron2, flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/775?usp=email

to look at the new patch set (#5).

Change subject: t_server_null: forcibly kill misbehaving servers
......................................................................

t_server_null: forcibly kill misbehaving servers

Change-Id Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb

---
M tests/t_server_null.sh
M tests/t_server_null_default.rc
M tests/t_server_null_server.sh

3 files changed, 20 insertions(+), 7 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/75/775/5

tests/t_server_null.sh +7 -1
index 7627edf..8fe1660 100755
@@ -67,4 +67,10 @@
 # pre and post ifconfig output does not match.
 wait
 
-exit $retval
+. ./t_server_null_default.rc
+
+if [ -e $SERVER_KILL_FAIL_FILE ]; then
+    exit 1
+else
+    exit $retval
+fi
tests/t_server_null_default.rc +4 -0
index 825bb52..cbf4877 100755
@@ -20,6 +20,10 @@
 SERVER_KEY="${sample_keys}/server.key"
 TA="${sample_keys}/ta.key"
 
+# Used to detect if graceful kill of any server instance failed during the test
+# run
+SERVER_KILL_FAIL_FILE=".t_server_null_server.kill_failed"
+
 # Test server configurations
 MAX_CLIENTS="10"
 CLIENT_MATCH="Test-Client"
tests/t_server_null_server.sh +9 -6
index 10bb44b..4654ccb 100755
@@ -36,6 +36,9 @@
 # Load local configuration, if any
 test -r ./t_server_null.rc && . ./t_server_null.rc
 
+# Remove server kill failure marker file, if any
+rm -f $SERVER_KILL_FAIL_FILE
+
 # Launch test servers
 for SUF in $TEST_SERVER_LIST
 do
@@ -87,11 +90,8 @@
         continue
     fi
 
-    if [ -z "${RUN_SUDO}" ]; then
-        $KILL_EXEC "${SERVER_PID}"
-    else
-        $RUN_SUDO $KILL_EXEC "${SERVER_PID}"
-    fi
+    # Attempt to kill the OpenVPN server gracefully with SIGTERM
+    $RUN_SUDO $KILL_EXEC "${SERVER_PID}"
 
     count=0
     maxcount=75
@@ -102,7 +102,10 @@
         sleep 0.2
     done
 
+    # If server is still up send a SIGKILL
     if [ $count -ge $maxcount ]; then
-        echo "WARNING: could not kill server with pid ${SERVER_PID}!"
+        $RUN_SUDO $KILL_EXEC -9 "${SERVER_PID}"
+        echo "ERROR: had to send SIGKILL to server with pid ${SERVER_PID}!"
+        touch $SERVER_KILL_FAIL_FILE
     fi
 done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/775?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb
Gerrit-Change-Number: 775
Gerrit-PatchSet: 5
Gerrit-Owner: mattock <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mattock <[email protected]...>
Gerrit-MessageType: newpatchset

#8 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, mattock, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/775?usp=email )

Change subject: t_server_null: forcibly kill misbehaving servers
......................................................................

Patch Set 5: Code-Review-2

(2 comments)

Patchset:

PS5:
It fails to see "does the process still live?" due to ps -p, see comment at the corresponding line. Changing that to RUN_SUDO kill -0 $SERVER_PID 2>/dev/null yields the desired result (server hacked to maliciously ignore SIGTERM 2x)

```
Waiting for servers to exit
ERROR: had to send SIGKILL to server with pid 10186!
ERROR: had to send SIGKILL to server with pid 10189!
FAIL: t_server_null.sh
```

now, while at it, we should actually print which server is "10186" and "10189" so it's easier to find the right log...

File tests/t_server_null_server.sh:

http://gerrit.openvpn.net/c/openvpn/+/775/comment/3af78b34_8263c5b3 :
PS5, Line 100: ps -p "${SERVER_PID}" > /dev/null || break
this does not work on systems where root processes are not visible to normal users, like "FreeBSD with security.bsd.see_other_uids=0" set. We've been here before - testing for "does the process still live?" needs to be done with $RUN_SUDO kill -0 $SERVER_PID

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/775?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb
Gerrit-Change-Number: 775
Gerrit-PatchSet: 5
Gerrit-Owner: mattock <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mattock <[email protected]...>
Gerrit-Comment-Date: Thu, 24 Oct 2024 18:41:55 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#9 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, mattock, plaisthos.

Hello cron2, flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/775?usp=email

to look at the new patch set (#6).

Change subject: t_server_null: forcibly kill misbehaving servers
......................................................................

t_server_null: forcibly kill misbehaving servers

Change-Id Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb

---
M tests/t_server_null.sh
M tests/t_server_null_default.rc
M tests/t_server_null_server.sh

3 files changed, 22 insertions(+), 8 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/75/775/6

tests/t_server_null.sh +7 -1
index 7627edf..8fe1660 100755
@@ -67,4 +67,10 @@
 # pre and post ifconfig output does not match.
 wait
 
-exit $retval
+. ./t_server_null_default.rc
+
+if [ -e $SERVER_KILL_FAIL_FILE ]; then
+    exit 1
+else
+    exit $retval
+fi
tests/t_server_null_default.rc +4 -0
index 825bb52..cbf4877 100755
@@ -20,6 +20,10 @@
 SERVER_KEY="${sample_keys}/server.key"
 TA="${sample_keys}/ta.key"
 
+# Used to detect if graceful kill of any server instance failed during the test
+# run
+SERVER_KILL_FAIL_FILE=".t_server_null_server.kill_failed"
+
 # Test server configurations
 MAX_CLIENTS="10"
 CLIENT_MATCH="Test-Client"
tests/t_server_null_server.sh +11 -7
index 10bb44b..61c9a4a 100755
@@ -36,6 +36,9 @@
 # Load local configuration, if any
 test -r ./t_server_null.rc && . ./t_server_null.rc
 
+# Remove server kill failure marker file, if any
+rm -f $SERVER_KILL_FAIL_FILE
+
 # Launch test servers
 for SUF in $TEST_SERVER_LIST
 do
@@ -77,6 +80,7 @@
 # Make sure that the server processes are truly dead before exiting.  If a
 # server process does not exit in 15 seconds assume it never will, move on and
 # hope for the best.
+
 echo "Waiting for servers to exit"
 for PID_FILE in $server_pid_files
 do
@@ -87,22 +91,22 @@
         continue
     fi
 
-    if [ -z "${RUN_SUDO}" ]; then
-        $KILL_EXEC "${SERVER_PID}"
-    else
-        $RUN_SUDO $KILL_EXEC "${SERVER_PID}"
-    fi
+    # Attempt to kill the OpenVPN server gracefully with SIGTERM
+    $RUN_SUDO $KILL_EXEC "${SERVER_PID}"
 
     count=0
     maxcount=75
     while [ $count -le $maxcount ]
     do
-        ps -p "${SERVER_PID}" > /dev/null || break
+        $RUN_SUDO kill -0 "${SERVER_PID}" 2> /dev/null || break
         count=$(( count + 1))
         sleep 0.2
     done
 
+    # If server is still up send a SIGKILL
     if [ $count -ge $maxcount ]; then
-        echo "WARNING: could not kill server with pid ${SERVER_PID}!"
+        $RUN_SUDO $KILL_EXEC -9 "${SERVER_PID}"
+        echo "ERROR: had to send SIGKILL to server with pid ${SERVER_PID}!"
+        touch $SERVER_KILL_FAIL_FILE
     fi
 done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/775?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb
Gerrit-Change-Number: 775
Gerrit-PatchSet: 6
Gerrit-Owner: mattock <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mattock <[email protected]...>
Gerrit-MessageType: newpatchset

#10 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, mattock, plaisthos.

Hello cron2, flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/775?usp=email

to look at the new patch set (#7).

Change subject: t_server_null: forcibly kill misbehaving servers
......................................................................

t_server_null: forcibly kill misbehaving servers

Change-Id Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb

---
M tests/t_server_null.sh
M tests/t_server_null_default.rc
M tests/t_server_null_server.sh

3 files changed, 25 insertions(+), 8 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/75/775/7

tests/t_server_null.sh +7 -1
index 7627edf..8fe1660 100755
@@ -67,4 +67,10 @@
 # pre and post ifconfig output does not match.
 wait
 
-exit $retval
+. ./t_server_null_default.rc
+
+if [ -e $SERVER_KILL_FAIL_FILE ]; then
+    exit 1
+else
+    exit $retval
+fi
tests/t_server_null_default.rc +4 -0
index 825bb52..cbf4877 100755
@@ -20,6 +20,10 @@
 SERVER_KEY="${sample_keys}/server.key"
 TA="${sample_keys}/ta.key"
 
+# Used to detect if graceful kill of any server instance failed during the test
+# run
+SERVER_KILL_FAIL_FILE=".t_server_null_server.kill_failed"
+
 # Test server configurations
 MAX_CLIENTS="10"
 CLIENT_MATCH="Test-Client"
tests/t_server_null_server.sh +14 -7
index 10bb44b..8c3faad 100755
@@ -36,6 +36,9 @@
 # Load local configuration, if any
 test -r ./t_server_null.rc && . ./t_server_null.rc
 
+# Remove server kill failure marker file, if any
+rm -f $SERVER_KILL_FAIL_FILE
+
 # Launch test servers
 for SUF in $TEST_SERVER_LIST
 do
@@ -77,6 +80,7 @@
 # Make sure that the server processes are truly dead before exiting.  If a
 # server process does not exit in 15 seconds assume it never will, move on and
 # hope for the best.
+
 echo "Waiting for servers to exit"
 for PID_FILE in $server_pid_files
 do
@@ -87,22 +91,25 @@
         continue
     fi
 
-    if [ -z "${RUN_SUDO}" ]; then
-        $KILL_EXEC "${SERVER_PID}"
-    else
-        $RUN_SUDO $KILL_EXEC "${SERVER_PID}"
-    fi
+    # Attempt to kill the OpenVPN server gracefully with SIGTERM
+    $RUN_SUDO $KILL_EXEC "${SERVER_PID}"
 
     count=0
     maxcount=75
     while [ $count -le $maxcount ]
     do
-        ps -p "${SERVER_PID}" > /dev/null || break
+        $RUN_SUDO kill -0 "${SERVER_PID}" 2> /dev/null || break
         count=$(( count + 1))
         sleep 0.2
     done
 
+    # If server is still up send a SIGKILL
     if [ $count -ge $maxcount ]; then
-        echo "WARNING: could not kill server with pid ${SERVER_PID}!"
+        $RUN_SUDO $KILL_EXEC -9 "${SERVER_PID}"
+        SERVER_NAME=$(basename $PID_FILE|cut -d . -f 1)
+        echo "ERROR: had to send SIGKILL to server ${SERVER_NAME} with pid ${SERVER_PID}!"
+        echo "Tail of server log:"
+        tail -n 20 "${SERVER_NAME}.log"
+        touch $SERVER_KILL_FAIL_FILE
     fi
 done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/775?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb
Gerrit-Change-Number: 775
Gerrit-PatchSet: 7
Gerrit-Owner: mattock <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mattock <[email protected]...>
Gerrit-MessageType: newpatchset

#11 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, mattock, plaisthos.

Hello cron2, flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/775?usp=email

to look at the new patch set (#8).

Change subject: t_server_null: forcibly kill misbehaving servers
......................................................................

t_server_null: forcibly kill misbehaving servers

Change-Id Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb

---
M tests/t_server_null.sh
M tests/t_server_null_default.rc
M tests/t_server_null_server.sh

3 files changed, 25 insertions(+), 8 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/75/775/8

tests/t_server_null.sh +7 -1
index d4311d4..3c0fc4b 100755
@@ -71,4 +71,10 @@
 # pre and post ifconfig output does not match.
 wait
 
-exit $retval
+. ./t_server_null_default.rc
+
+if [ -e $SERVER_KILL_FAIL_FILE ]; then
+    exit 1
+else
+    exit $retval
+fi
tests/t_server_null_default.rc +4 -0
index 825bb52..cbf4877 100755
@@ -20,6 +20,10 @@
 SERVER_KEY="${sample_keys}/server.key"
 TA="${sample_keys}/ta.key"
 
+# Used to detect if graceful kill of any server instance failed during the test
+# run
+SERVER_KILL_FAIL_FILE=".t_server_null_server.kill_failed"
+
 # Test server configurations
 MAX_CLIENTS="10"
 CLIENT_MATCH="Test-Client"
tests/t_server_null_server.sh +14 -7
index f8ba3a3..4d86f46 100755
@@ -34,6 +34,9 @@
 # Load local configuration, if any
 test -r ./t_server_null.rc && . ./t_server_null.rc
 
+# Remove server kill failure marker file, if any
+rm -f $SERVER_KILL_FAIL_FILE
+
 # Launch test servers
 for SUF in $TEST_SERVER_LIST
 do
@@ -75,6 +78,7 @@
 # Make sure that the server processes are truly dead before exiting.  If a
 # server process does not exit in 15 seconds assume it never will, move on and
 # hope for the best.
+
 echo "Waiting for servers to exit"
 for PID_FILE in $server_pid_files
 do
@@ -85,22 +89,25 @@
         continue
     fi
 
-    if [ -z "${RUN_SUDO}" ]; then
-        $KILL_EXEC "${SERVER_PID}"
-    else
-        $RUN_SUDO $KILL_EXEC "${SERVER_PID}"
-    fi
+    # Attempt to kill the OpenVPN server gracefully with SIGTERM
+    $RUN_SUDO $KILL_EXEC "${SERVER_PID}"
 
     count=0
     maxcount=75
     while [ $count -le $maxcount ]
     do
-        ps -p "${SERVER_PID}" > /dev/null || break
+        $RUN_SUDO kill -0 "${SERVER_PID}" 2> /dev/null || break
         count=$(( count + 1))
         sleep 0.2
     done
 
+    # If server is still up send a SIGKILL
     if [ $count -ge $maxcount ]; then
-        echo "WARNING: could not kill server with pid ${SERVER_PID}!"
+        $RUN_SUDO $KILL_EXEC -9 "${SERVER_PID}"
+        SERVER_NAME=$(basename $PID_FILE|cut -d . -f 1)
+        echo "ERROR: had to send SIGKILL to server ${SERVER_NAME} with pid ${SERVER_PID}!"
+        echo "Tail of server log:"
+        tail -n 20 "${t_server_null_logdir}/${SERVER_NAME}.log"
+        touch $SERVER_KILL_FAIL_FILE
     fi
 done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/775?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb
Gerrit-Change-Number: 775
Gerrit-PatchSet: 8
Gerrit-Owner: mattock <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mattock <[email protected]...>
Gerrit-MessageType: newpatchset

#12 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, mattock, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/775?usp=email )

Change subject: t_server_null: forcibly kill misbehaving servers
......................................................................

Patch Set 8: Code-Review-2

(4 comments)

Patchset:

PS8:
getting closer

File tests/t_server_null.sh:

http://gerrit.openvpn.net/c/openvpn/+/775/comment/eede43c8_d60b792c :
PS8, Line 72: wait
remembering the pid of the t_server_null_server.sh job after launching (server_sh_pid=$!) and then calling wait $server_sh_pid will nicely deliver child program exit status in $!, without having to dance around with an extra file that needs to be created, rc-filed, tested-for.

wait without a pid specified does not return child return code, which is somewhat annoying.

File tests/t_server_null_server.sh:

http://gerrit.openvpn.net/c/openvpn/+/775/comment/ea5470ba_cd74abb4 :
PS3, Line 106: fi

Quoted 1 line

I think we should make this a "test fail". […]

Done

File tests/t_server_null_server.sh:

http://gerrit.openvpn.net/c/openvpn/+/775/comment/81b60a59_9f45dafb :
PS8, Line 110: tail -n 20 "${t_server_null_logdir}/${SERVER_NAME}.log"
this wants a $RUN_SUDO because root-owned logs are not readable otherwise (or we need to precreate them before openvpn startup)...

```
Waiting for servers to exit
ERROR: had to send SIGKILL to server t_server_null_server-1194_udp with pid 23977!
Tail of server log:
tail: t_server_null-fbsd14bb.ov.greenie.net-20241025-105632/t_server_null_server-1194_udp.log: Permission denied
ERROR: had to send SIGKILL to server t_server_null_server-1195_tcp with pid 23983!
Tail of server log:
tail: t_server_null-fbsd14bb.ov.greenie.net-20241025-105632/t_server_null_server-1195_tcp.log: Permission denied
FAIL: t_server_null.sh
```

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/775?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb
Gerrit-Change-Number: 775
Gerrit-PatchSet: 8
Gerrit-Owner: mattock <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mattock <[email protected]...>
Gerrit-Comment-Date: Fri, 25 Oct 2024 09:02:19 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment

#13 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, mattock, plaisthos.

Hello cron2, flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/775?usp=email

to look at the new patch set (#9).

Change subject: t_server_null: forcibly kill misbehaving servers
......................................................................

t_server_null: forcibly kill misbehaving servers

Change-Id Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb

---
M tests/t_server_null.sh
M tests/t_server_null_client.sh
M tests/t_server_null_default.rc
M tests/t_server_null_server.sh

4 files changed, 30 insertions(+), 10 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/75/775/9

tests/t_server_null.sh +7 -1
index d4311d4..3c0fc4b 100755
@@ -71,4 +71,10 @@
 # pre and post ifconfig output does not match.
 wait
 
-exit $retval
+. ./t_server_null_default.rc
+
+if [ -e $SERVER_KILL_FAIL_FILE ]; then
+    exit 1
+else
+    exit $retval
+fi
tests/t_server_null_client.sh +2 -2
index 846f790..2210e63 100755
@@ -53,11 +53,11 @@
         echo "PASS ${test_name} (test failure)"
     elif [ $exit_code -eq 0 ] && [ "${should_pass}" = "no" ]; then
         echo "FAIL ${test_name} (test failure)"
-        cat "${log}"
+        cat "${t_server_null_logdir}/${log}"
         retval=1
     elif [ $exit_code -eq 1 ] && [ "${should_pass}" = "yes" ]; then
         echo "FAIL ${test_name}"
-        cat "${log}"
+        cat "${t_server_null_logdir}/${log}"
         retval=1
     fi
 }
tests/t_server_null_default.rc +4 -0
index 825bb52..cbf4877 100755
@@ -20,6 +20,10 @@
 SERVER_KEY="${sample_keys}/server.key"
 TA="${sample_keys}/ta.key"
 
+# Used to detect if graceful kill of any server instance failed during the test
+# run
+SERVER_KILL_FAIL_FILE=".t_server_null_server.kill_failed"
+
 # Test server configurations
 MAX_CLIENTS="10"
 CLIENT_MATCH="Test-Client"
tests/t_server_null_server.sh +17 -7
index f8ba3a3..ab01dd2 100755
@@ -8,6 +8,9 @@
     status="${server_name}.status"
     pid="${server_name}.pid"
 
+    # Allow reading this file even umask values are strict
+    touch "$log"
+
     if [ -z "${RUN_SUDO}" ]; then
         "${server_exec}" \
          $server_conf \
@@ -34,6 +37,9 @@
 # Load local configuration, if any
 test -r ./t_server_null.rc && . ./t_server_null.rc
 
+# Remove server kill failure marker file, if any
+rm -f $SERVER_KILL_FAIL_FILE
+
 # Launch test servers
 for SUF in $TEST_SERVER_LIST
 do
@@ -75,6 +81,7 @@
 # Make sure that the server processes are truly dead before exiting.  If a
 # server process does not exit in 15 seconds assume it never will, move on and
 # hope for the best.
+
 echo "Waiting for servers to exit"
 for PID_FILE in $server_pid_files
 do
@@ -85,22 +92,25 @@
         continue
     fi
 
-    if [ -z "${RUN_SUDO}" ]; then
-        $KILL_EXEC "${SERVER_PID}"
-    else
-        $RUN_SUDO $KILL_EXEC "${SERVER_PID}"
-    fi
+    # Attempt to kill the OpenVPN server gracefully with SIGTERM
+    $RUN_SUDO $KILL_EXEC "${SERVER_PID}"
 
     count=0
     maxcount=75
     while [ $count -le $maxcount ]
     do
-        ps -p "${SERVER_PID}" > /dev/null || break
+        $RUN_SUDO kill -0 "${SERVER_PID}" 2> /dev/null || break
         count=$(( count + 1))
         sleep 0.2
     done
 
+    # If server is still up send a SIGKILL
     if [ $count -ge $maxcount ]; then
-        echo "WARNING: could not kill server with pid ${SERVER_PID}!"
+        $RUN_SUDO $KILL_EXEC -9 "${SERVER_PID}"
+        SERVER_NAME=$(basename $PID_FILE|cut -d . -f 1)
+        echo "ERROR: had to send SIGKILL to server ${SERVER_NAME} with pid ${SERVER_PID}!"
+        echo "Tail of server log:"
+        tail -n 20 "${t_server_null_logdir}/${SERVER_NAME}.log"
+        touch $SERVER_KILL_FAIL_FILE
     fi
 done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/775?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb
Gerrit-Change-Number: 775
Gerrit-PatchSet: 9
Gerrit-Owner: mattock <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mattock <[email protected]...>
Gerrit-MessageType: newpatchset

#14 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, mattock, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/775?usp=email )

Change subject: t_server_null: forcibly kill misbehaving servers
......................................................................

Patch Set 9: Code-Review+2

(2 comments)

Patchset:

PS9:
Waiting for servers to exit
ERROR: had to send SIGKILL to server t_server_null_server-1194_udp with pid 66227! Tail of server log:

2024-10-25 12:33:41 127.0.0.1:57874 peer info: IV_PROTO=2974
2024-10-25 12:33:41 127.0.0.1:57874 peer info: IV_LZO_STUB=1
...
2024-10-25 12:34:18 MPS: ignore signal

FAIL: t_server_null.sh

File tests/t_server_null_server.sh:

http://gerrit.openvpn.net/c/openvpn/+/775/comment/6fdd0172_a2fa6e00 :
PS8, Line 110: tail -n 20 "${t_server_null_logdir}/${SERVER_NAME}.log"

Quoted 1 line

this wants a $RUN_SUDO because root-owned logs are not readable otherwise (or we need to precreate […]

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/775?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb
Gerrit-Change-Number: 775
Gerrit-PatchSet: 9
Gerrit-Owner: mattock <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: mattock <[email protected]...>
Gerrit-Comment-Date: Fri, 25 Oct 2024 10:34:56 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment

#15 lore raw

PATCH v9 1/1 t_server_null: forcibly kill misbehaving servers

In reply to a message not in the archive

From: Samuli Seppänen <[email protected]...>

Change-Id Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb

---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/775
This mail reflects revision 9 of this Change.

Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>

tests/t_server_null.sh +7 -1
index d4311d4..3c0fc4b 100755
@@ -71,4 +71,10 @@
 # pre and post ifconfig output does not match.
 wait
 
-exit $retval
+. ./t_server_null_default.rc
+
+if [ -e $SERVER_KILL_FAIL_FILE ]; then
+    exit 1
+else
+    exit $retval
+fi
tests/t_server_null_client.sh +2 -2
index 846f790..2210e63 100755
@@ -53,11 +53,11 @@
         echo "PASS ${test_name} (test failure)"
     elif [ $exit_code -eq 0 ] && [ "${should_pass}" = "no" ]; then
         echo "FAIL ${test_name} (test failure)"
-        cat "${log}"
+        cat "${t_server_null_logdir}/${log}"
         retval=1
     elif [ $exit_code -eq 1 ] && [ "${should_pass}" = "yes" ]; then
         echo "FAIL ${test_name}"
-        cat "${log}"
+        cat "${t_server_null_logdir}/${log}"
         retval=1
     fi
 }
tests/t_server_null_default.rc +4 -0
index 825bb52..cbf4877 100755
@@ -20,6 +20,10 @@
 SERVER_KEY="${sample_keys}/server.key"
 TA="${sample_keys}/ta.key"
 
+# Used to detect if graceful kill of any server instance failed during the test
+# run
+SERVER_KILL_FAIL_FILE=".t_server_null_server.kill_failed"
+
 # Test server configurations
 MAX_CLIENTS="10"
 CLIENT_MATCH="Test-Client"
tests/t_server_null_server.sh +17 -7
index f8ba3a3..ab01dd2 100755
@@ -8,6 +8,9 @@
     status="${server_name}.status"
     pid="${server_name}.pid"
 
+    # Allow reading this file even umask values are strict
+    touch "$log"
+
     if [ -z "${RUN_SUDO}" ]; then
         "${server_exec}" \
          $server_conf \
@@ -34,6 +37,9 @@
 # Load local configuration, if any
 test -r ./t_server_null.rc && . ./t_server_null.rc
 
+# Remove server kill failure marker file, if any
+rm -f $SERVER_KILL_FAIL_FILE
+
 # Launch test servers
 for SUF in $TEST_SERVER_LIST
 do
@@ -75,6 +81,7 @@
 # Make sure that the server processes are truly dead before exiting.  If a
 # server process does not exit in 15 seconds assume it never will, move on and
 # hope for the best.
+
 echo "Waiting for servers to exit"
 for PID_FILE in $server_pid_files
 do
@@ -85,22 +92,25 @@
         continue
     fi
 
-    if [ -z "${RUN_SUDO}" ]; then
-        $KILL_EXEC "${SERVER_PID}"
-    else
-        $RUN_SUDO $KILL_EXEC "${SERVER_PID}"
-    fi
+    # Attempt to kill the OpenVPN server gracefully with SIGTERM
+    $RUN_SUDO $KILL_EXEC "${SERVER_PID}"
 
     count=0
     maxcount=75
     while [ $count -le $maxcount ]
     do
-        ps -p "${SERVER_PID}" > /dev/null || break
+        $RUN_SUDO kill -0 "${SERVER_PID}" 2> /dev/null || break
         count=$(( count + 1))
         sleep 0.2
     done
 
+    # If server is still up send a SIGKILL
     if [ $count -ge $maxcount ]; then
-        echo "WARNING: could not kill server with pid ${SERVER_PID}!"
+        $RUN_SUDO $KILL_EXEC -9 "${SERVER_PID}"
+        SERVER_NAME=$(basename $PID_FILE|cut -d . -f 1)
+        echo "ERROR: had to send SIGKILL to server ${SERVER_NAME} with pid ${SERVER_PID}!"
+        echo "Tail of server log:"
+        tail -n 20 "${t_server_null_logdir}/${SERVER_NAME}.log"
+        touch $SERVER_KILL_FAIL_FILE
     fi
 done
#16 lore raw

[Openvpn-devel] [PATCH applied] Re: t_server_null: forcibly kill misbehaving servers

Tested this quite extensively up to v9 ;-) - by intentionally making openvpn server misbehave (ignoring first 2 signals sent to it) with this patch

src/openvpn/multi.c +4 -0
@@ -3864,6 +3864,10 @@ multi_push_restart_schedule_exit(struct multi_context *m, bool next_server)
 bool
 multi_process_signal(struct multi_context *m)
 {
+static int n=0;
+    if (n++ < 1 )
+       { msg(M_INFO, "MPS: ignore signal"); signal_reset(m->top.sig,0); return false; }
+
 

.. and v9 now properly reports this as "test fail" plus shows the (previously root-owned and unreadable) log file, so we can more easily see from the buildbot fail mails what happened and if this is "infra problem" or "incoming patch problem".

BB + GHA agree that this is fine, for the non-broken-server case ;-)

Your patch has been applied to the master branch.

commit 37db7fe37afb555de651314a04c537fd7fbaa280

Author: Samuli Seppänen
Date:   Fri Oct 25 12:36:31 2024 +0200
     t_server_null: forcibly kill misbehaving servers

     Signed-off-by: Samuli Seppänen <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg29655.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#17 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#10) to the change originally created by mattock. ( http://gerrit.openvpn.net/c/openvpn/+/775?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by cron2

Change subject: t_server_null: forcibly kill misbehaving servers
......................................................................

t_server_null: forcibly kill misbehaving servers

Change-Id Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg29655.html

---
M tests/t_server_null.sh
M tests/t_server_null_client.sh
M tests/t_server_null_default.rc
M tests/t_server_null_server.sh

4 files changed, 30 insertions(+), 10 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/75/775/10

tests/t_server_null.sh +7 -1
index d4311d4..3c0fc4b 100755
@@ -71,4 +71,10 @@
 # pre and post ifconfig output does not match.
 wait
 
-exit $retval
+. ./t_server_null_default.rc
+
+if [ -e $SERVER_KILL_FAIL_FILE ]; then
+    exit 1
+else
+    exit $retval
+fi
tests/t_server_null_client.sh +2 -2
index 846f790..2210e63 100755
@@ -53,11 +53,11 @@
         echo "PASS ${test_name} (test failure)"
     elif [ $exit_code -eq 0 ] && [ "${should_pass}" = "no" ]; then
         echo "FAIL ${test_name} (test failure)"
-        cat "${log}"
+        cat "${t_server_null_logdir}/${log}"
         retval=1
     elif [ $exit_code -eq 1 ] && [ "${should_pass}" = "yes" ]; then
         echo "FAIL ${test_name}"
-        cat "${log}"
+        cat "${t_server_null_logdir}/${log}"
         retval=1
     fi
 }
tests/t_server_null_default.rc +4 -0
index 825bb52..cbf4877 100755
@@ -20,6 +20,10 @@
 SERVER_KEY="${sample_keys}/server.key"
 TA="${sample_keys}/ta.key"
 
+# Used to detect if graceful kill of any server instance failed during the test
+# run
+SERVER_KILL_FAIL_FILE=".t_server_null_server.kill_failed"
+
 # Test server configurations
 MAX_CLIENTS="10"
 CLIENT_MATCH="Test-Client"
tests/t_server_null_server.sh +17 -7
index f8ba3a3..ab01dd2 100755
@@ -8,6 +8,9 @@
     status="${server_name}.status"
     pid="${server_name}.pid"
 
+    # Allow reading this file even umask values are strict
+    touch "$log"
+
     if [ -z "${RUN_SUDO}" ]; then
         "${server_exec}" \
          $server_conf \
@@ -34,6 +37,9 @@
 # Load local configuration, if any
 test -r ./t_server_null.rc && . ./t_server_null.rc
 
+# Remove server kill failure marker file, if any
+rm -f $SERVER_KILL_FAIL_FILE
+
 # Launch test servers
 for SUF in $TEST_SERVER_LIST
 do
@@ -75,6 +81,7 @@
 # Make sure that the server processes are truly dead before exiting.  If a
 # server process does not exit in 15 seconds assume it never will, move on and
 # hope for the best.
+
 echo "Waiting for servers to exit"
 for PID_FILE in $server_pid_files
 do
@@ -85,22 +92,25 @@
         continue
     fi
 
-    if [ -z "${RUN_SUDO}" ]; then
-        $KILL_EXEC "${SERVER_PID}"
-    else
-        $RUN_SUDO $KILL_EXEC "${SERVER_PID}"
-    fi
+    # Attempt to kill the OpenVPN server gracefully with SIGTERM
+    $RUN_SUDO $KILL_EXEC "${SERVER_PID}"
 
     count=0
     maxcount=75
     while [ $count -le $maxcount ]
     do
-        ps -p "${SERVER_PID}" > /dev/null || break
+        $RUN_SUDO kill -0 "${SERVER_PID}" 2> /dev/null || break
         count=$(( count + 1))
         sleep 0.2
     done
 
+    # If server is still up send a SIGKILL
     if [ $count -ge $maxcount ]; then
-        echo "WARNING: could not kill server with pid ${SERVER_PID}!"
+        $RUN_SUDO $KILL_EXEC -9 "${SERVER_PID}"
+        SERVER_NAME=$(basename $PID_FILE|cut -d . -f 1)
+        echo "ERROR: had to send SIGKILL to server ${SERVER_NAME} with pid ${SERVER_PID}!"
+        echo "Tail of server log:"
+        tail -n 20 "${t_server_null_logdir}/${SERVER_NAME}.log"
+        touch $SERVER_KILL_FAIL_FILE
     fi
 done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/775?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb
Gerrit-Change-Number: 775
Gerrit-PatchSet: 10
Gerrit-Owner: mattock <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset

#18 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/775?usp=email )

Change subject: t_server_null: forcibly kill misbehaving servers
......................................................................

t_server_null: forcibly kill misbehaving servers

Change-Id Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg29655.html

---
M tests/t_server_null.sh
M tests/t_server_null_client.sh
M tests/t_server_null_default.rc
M tests/t_server_null_server.sh

4 files changed, 30 insertions(+), 10 deletions(-)
tests/t_server_null.sh +7 -1
index d4311d4..3c0fc4b 100755
@@ -71,4 +71,10 @@
 # pre and post ifconfig output does not match.
 wait
 
-exit $retval
+. ./t_server_null_default.rc
+
+if [ -e $SERVER_KILL_FAIL_FILE ]; then
+    exit 1
+else
+    exit $retval
+fi
tests/t_server_null_client.sh +2 -2
index 846f790..2210e63 100755
@@ -53,11 +53,11 @@
         echo "PASS ${test_name} (test failure)"
     elif [ $exit_code -eq 0 ] && [ "${should_pass}" = "no" ]; then
         echo "FAIL ${test_name} (test failure)"
-        cat "${log}"
+        cat "${t_server_null_logdir}/${log}"
         retval=1
     elif [ $exit_code -eq 1 ] && [ "${should_pass}" = "yes" ]; then
         echo "FAIL ${test_name}"
-        cat "${log}"
+        cat "${t_server_null_logdir}/${log}"
         retval=1
     fi
 }
tests/t_server_null_default.rc +4 -0
index 825bb52..cbf4877 100755
@@ -20,6 +20,10 @@
 SERVER_KEY="${sample_keys}/server.key"
 TA="${sample_keys}/ta.key"
 
+# Used to detect if graceful kill of any server instance failed during the test
+# run
+SERVER_KILL_FAIL_FILE=".t_server_null_server.kill_failed"
+
 # Test server configurations
 MAX_CLIENTS="10"
 CLIENT_MATCH="Test-Client"
tests/t_server_null_server.sh +17 -7
index f8ba3a3..ab01dd2 100755
@@ -8,6 +8,9 @@
     status="${server_name}.status"
     pid="${server_name}.pid"
 
+    # Allow reading this file even umask values are strict
+    touch "$log"
+
     if [ -z "${RUN_SUDO}" ]; then
         "${server_exec}" \
          $server_conf \
@@ -34,6 +37,9 @@
 # Load local configuration, if any
 test -r ./t_server_null.rc && . ./t_server_null.rc
 
+# Remove server kill failure marker file, if any
+rm -f $SERVER_KILL_FAIL_FILE
+
 # Launch test servers
 for SUF in $TEST_SERVER_LIST
 do
@@ -75,6 +81,7 @@
 # Make sure that the server processes are truly dead before exiting.  If a
 # server process does not exit in 15 seconds assume it never will, move on and
 # hope for the best.
+
 echo "Waiting for servers to exit"
 for PID_FILE in $server_pid_files
 do
@@ -85,22 +92,25 @@
         continue
     fi
 
-    if [ -z "${RUN_SUDO}" ]; then
-        $KILL_EXEC "${SERVER_PID}"
-    else
-        $RUN_SUDO $KILL_EXEC "${SERVER_PID}"
-    fi
+    # Attempt to kill the OpenVPN server gracefully with SIGTERM
+    $RUN_SUDO $KILL_EXEC "${SERVER_PID}"
 
     count=0
     maxcount=75
     while [ $count -le $maxcount ]
     do
-        ps -p "${SERVER_PID}" > /dev/null || break
+        $RUN_SUDO kill -0 "${SERVER_PID}" 2> /dev/null || break
         count=$(( count + 1))
         sleep 0.2
     done
 
+    # If server is still up send a SIGKILL
     if [ $count -ge $maxcount ]; then
-        echo "WARNING: could not kill server with pid ${SERVER_PID}!"
+        $RUN_SUDO $KILL_EXEC -9 "${SERVER_PID}"
+        SERVER_NAME=$(basename $PID_FILE|cut -d . -f 1)
+        echo "ERROR: had to send SIGKILL to server ${SERVER_NAME} with pid ${SERVER_PID}!"
+        echo "Tail of server log:"
+        tail -n 20 "${t_server_null_logdir}/${SERVER_NAME}.log"
+        touch $SERVER_KILL_FAIL_FILE
     fi
 done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/775?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic0f98cd3b87a7b86e032e63167ac9036f7c08fcb
Gerrit-Change-Number: 775
Gerrit-PatchSet: 10
Gerrit-Owner: mattock <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged